home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.4 KB | 90 lines | [TEXT/ttxt] |
- --<<<-
- -- Filename:
- -- animate.sx
-
- -- Other Files Required:
- -- This file is loaded by loadme.sx in the animate folder.
-
- -- Purpose:
- -- animate.sx contains the class definition for Animation, a scripted class for doing
- -- simple animation.
-
- -- Specialized Classes:
- -- Animation
-
- -- Instructions to User:
- -- Class Animation is a subclass of TwoDShape which uses a clock to iterate through a
- -- series of stencils. The series may be any implicit-keyed collection of Stencil subclass
- -- instances. At each tick of the clock. the tick method is invoked on the Animation, which
- -- changes the boundary to the next stencil in the series. At the end of the series, the
- -- Animation automatically loops back to the beginning. If an endAction callback is specified,
- -- it is invoked at this time with authorData and self as the arguments.
- --
- -- EXAMPLE CREATION:
- -- new Animation series: #(bm1, bm2, bm3) animationClock: (new Clock scale:10)
- --
- -- PUBLIC PROTOCOL:
- -- start self
- -- stop self
-
- -- Author:
- -- Steve Mayer
- in module InternetFish
-
- class Animation(TwoDShape)
- instance variables
- series
- cell
- animationClock
- authorData
- endAction
- end
-
- method init self {class Animation} #key series: (#(new Oval x2:100 y2:100)) \
- animationClock: (new Clock scale:5) \
- endAction: (undefined) \
- autoStart: (true) ->
- (
- nextMethod self boundary:(series[1]) fill:blackBrush
- self.series := series
- self.cell := 1
- self.animationClock := animationClock
- addPeriodicCallBack self.animationClock (clk -> tick self clk) self.animationClock #() 1
- self.endAction := endAction
- if autoStart do start self
- return self
- )
-
- method start self {class Animation} ->
- (
- self.animationClock.rate := 1
- )
-
- method stop self {class Animation} ->
- (
- self.animationClock.rate := 0
- )
-
- method seriesEnded self {class Animation} ->
- (
- -- Execute endAction callback if there is one.
- if (self.endAction <> undefined) do
- self.endAction self.authorData self
- )
-
- -- Method tick is called at each tick of the animation clock. It changes
- -- the animation cell to the next cell in the series.
- method tick self {class Animation} clk ->
- (
- -- Change to the appropriate cell
- self.boundary := self.series[self.cell]
-
- -- Get the next cell. Wrap around if at the end.
- self.cell := ((mod self.cell self.series.size) as Integer) + 1
-
- -- If at the end, call seriesEnded.
- if (self.cell = 1) do
- seriesEnded self
- )
- -- End of class definition for Animation.
-